Page({
    data: {
        y_arr_list: [],
        y_arr_arr: [],
        y_arr_listLimit: 0,
        
        y_arr_max_count: '',
        y_arr_max: [],
        y_arr_art: [],
        y_arr_wenda: [],
        base: 10,
        
        search: 'fl tab_tit_sel',
        search_wz: 'fl',
        search_wd: 'fl',
        search_type: '1',
    },
    
    onLoad: function (options) {
        console.log('title========'+options.title);
        var title=options.title;
        var type=options.type;
        if(type=="arr"){
            this.setData({ search_type: '1'})
            this.setData({ search: 'fl tab_tit_sel'})
            this.setData({ search_wz: 'fl'})
            this.setData({ search_wd: 'fl'})
        }
        if(type=="art"){
            this.setData({ search_type: '2'})
            this.setData({ search: 'fl'})
            this.setData({ search_wz: 'fl tab_tit_sel'})
            this.setData({ search_wd: 'fl'})
        }
        if(type=="wenda"){
            this.setData({ search_type: '3'})
            this.setData({ search: 'fl'})
            this.setData({ search_wz: 'fl'})
            this.setData({ search_wd: 'fl tab_tit_sel'})
        }

        this.setData({ title: title})
        this.yys_search(title,type,"0");
    },
    yys_search(title,type,num) {
        var timestamp = Date.parse(new Date());
        var that = this;
        //链接远程服务器
        swan.request({
            url: 'https://api.cndzys.com/index.php/yys_search', 
            method: 'GET',
            data: { title: title,search_type: type, num: num },
            header: { 'content-type': 'application/json' },
            success: function (res) {
                that.setData({ data_art: res.data.data_art})
                that.setData({ data_wenda: res.data.data_wenda})
                that.setData({ data_max: res.data.data_max})
                //that.setData({ max: res.data.max})
                if(that.data.search_type=="1"){
                    var y_arr_art = that.data.y_arr_art.concat(res.data.data_art)
                    var y_arr_wenda = that.data.y_arr_wenda.concat(res.data.data_wenda)
                    var y_arr_max = that.data.y_arr_max.concat(res.data.data_max)
                    var y_arr_maxcount = y_arr_max.length
                    that.setData({ y_arr_max: y_arr_max})
                    that.setData({ y_arr_maxcount: y_arr_maxcount})
                    that.setData({ y_arr_art: y_arr_art})
                    that.setData({ y_arr_wenda: y_arr_wenda})
                    console.log("y_arr_max");
                    console.log(y_arr_max);
                    console.log("y_arr_max_count");
                    console.log(y_arr_maxcount);
                    console.log("y_arr_art");
                    console.log(y_arr_art);
                }
                if(that.data.search_type=="2"){
                    var y_arr_art = that.data.y_arr_art.concat(res.data.data_art)
                    that.setData({y_arr_art: y_arr_art })
                    console.log(y_arr_art);
                }
                if(that.data.search_type=="3"){
                    var y_arr_wenda = that.data.y_arr_wenda.concat(res.data.data_wenda)
                    that.setData({y_arr_wenda: y_arr_wenda })
                    console.log(y_arr_wenda);
                }
            },
        });
    },
    onReachBottom: function () {
        console.log("我滑动到底部了");
        var search_type=this.data.search_type;
        var title=this.data.title;
        
        if(search_type=="1"){
            var num=this.data.y_arr_max.length;
            console.log("我滑动到底部了"+num+"分类是="+this.data.search_type);
            this.yys_search(title,"arr",num);
        }
        if(search_type=="2"){
            var num=this.data.y_arr_art.length;
            console.log("我滑动到底部了"+num+"分类是="+this.data.search_type);
            this.yys_search(title,"art",num);
        }
        if(search_type=="3"){
            var num=this.data.y_arr_wenda.length;
            console.log("我滑动到底部了"+num+"分类是="+this.data.search_type);
            this.yys_search(title,"wenda",num);
        }

    },
    search(event) {
        var title = event.currentTarget.id
        console.log("综合="+title);
        this.setData({ search_type: '1'})
        this.setData({ search: 'fl tab_tit_sel'})
        this.setData({ search_wz: 'fl'})
        this.setData({ search_wd: 'fl'})
        
        this.setData({ y_arr_max: []})
        this.setData({ y_arr_art: []})
        this.setData({ y_arr_wenda: []})

        this.yys_search(title,"arr",'0');
    },
    search_wz(event) {
        var title = event.currentTarget.id
        console.log("文章="+title);
        this.setData({ search_type: '2'})
        this.setData({ search: 'fl'})
        this.setData({ search_wz: 'fl tab_tit_sel'})
        this.setData({ search_wd: 'fl'})

        this.setData({ y_arr_max: []})
        this.setData({ y_arr_art: []})
        this.setData({ y_arr_wenda: []})
        this.yys_search(title,"art","0");
    },
    search_wd(event) {
        var title = event.currentTarget.id
        console.log("问答="+title);
        this.setData({ search_type: '3'})
        this.setData({ search: 'fl'})
        this.setData({ search_wz: 'fl'})
        this.setData({ search_wd: 'fl tab_tit_sel'})


        this.setData({ y_arr_max: []})
        this.setData({ y_arr_art: []})
        this.setData({ y_arr_wenda: []})
        this.yys_search(title,"wenda","0");
    },
    qandadetail(event) {
        var wenda_id = event.currentTarget.id
        swan.navigateTo({ url:'../qandadetail/qandadetail?wenda_id=' + wenda_id  });
    },
    articledetail(event) {
        var art_id = event.currentTarget.id
        swan.navigateTo({ url:'../articledetail/articledetail?art_id=' + art_id  });
    },
});
